import axios from 'axios'
import 'element-plus/theme-chalk/el-message.css'
import { ElMessage } from 'element-plus'

// axios基础封装
const httpInstance = axios.create({
    baseURL: '/api',
    timeout: 500000,
    headers: {
        'Content-Type': 'application/json'
    }
})

// axios请求拦截器
httpInstance.interceptors.request.use(config => {
    return config
}, e => Promise.reject(e))

// axios响应式拦截器
httpInstance.interceptors.response.use(res => res.data, e => {
    console.log(e)
    // 统一错误提示
    ElMessage({
        type: 'warning',
        message: e
    })
    return Promise.reject(e)
})

export default httpInstance